<html>
    <head>
        <title>提取PNR形成订单</title>
    </head>
    <body>
        <div id="rt_pnr_form">
        </div>
        <div id="rtOrdersGrid" class="x-form-item">
        </div>
        <div id="rtTicketsGrid" class="x-form-item">
        </div>
        <script>
            var current_order_id; //当前选择的order的id
            var current_ticket_id; //当前选择的ticket的id
            var current_order_status; //当前order的状态
            var current_ticket_status; //当前ticket的状态
            var ordersrow;
            var ticketsrow;
            Ext.onReady(function(){
                var pnrField = new Ext.form.TextField({
                    fieldLabel: 'PNR',
                    name: 'pnr',
                    allowBlank: false,
                    //anchor: '90%',
                    width: 80
                });

                //提交按钮
                var submitButton = new Ext.Button({
                    text: '提取',
                    handler: function(){
                        if (formPanel.form.isValid()) {
                            var pnr = pnrField.getValue();
                            if (pnr.length == 5) {
                                orderds.baseParams.pnr = pnr;
                                orderds.load();
                            }
                            else {
                                Ext.MessageBox.alert('提示信息', '输入的PNR有误,必须是5为字母或数字组成.');
                            }
                        }
                    }
                })

                var formPanel = new Ext.form.FormPanel({
                    //baseCls: 'x-plain',
                    labelWidth: 75,
                    width: '100%',
                    frame: true,
                    //title: '提取PNR信息形成订单',
                    labelAlign: 'right',
                    items: [{
                            layout: 'column',
                            border: false,
                            items: [{
                                    columnWidth: .2,
                                    layout: 'form',
                                    border: false,
                                    items: [pnrField]
                                }, {
                                    columnWidth: .3,
                                    layout: 'form',
                                    border: false,
                                    items: [submitButton]
                                }]
                        }]
                });

                formPanel.render('rt_pnr_form');

                //############## 订单Grid ##############
                var ordercm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
                        header: '编号',
                        dataIndex: 'id',
                        hidden: true
                    }, {
                        header: '订单编号',
                        dataIndex: 'order_no',
                        width: 120
                    }, {
                        header: 'PNR',
                        dataIndex: 'pnr',
                        width: 50
                     }, {
                        header: '订单状态',
                        dataIndex: 'status',
                        width: 60
                    }, {
                        header: '总金额',
                        dataIndex: 'price_sum',
                        width: 60
                    }, {
                        header: '航班号',
                        dataIndex: 'air_no',
                        width: 60
                    }, {
                        header: '城市对',
                        dataIndex: 'fromto',
                        width: 60
                    }, {
                        header: '乘机日期',
                        dataIndex: 'fly_date',
                        width: 90
                    }, {
                        header: '起飞(T)',
                        dataIndex: 'fly_time',
                        width: 50
                    }, {
                        header: '到达(T)',
                        dataIndex: 'arr_time',
                        width: 50
                    }, {
                        header: '舱位',
                        dataIndex: 'position',
                        width: 40
                    }, {
                        header: '预定时间',
                        dataIndex: 'created_at',
                        width: 120,
                        renderer: Ext.util.Format.dateRenderer('Y-m-d H:i')
                    }]);

                var orderds = new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: '/ticket/getOrderInfoByPnr'
                    }),
                    reader: new Ext.data.JsonReader({
                        root: 'root'
                    }, [{
                            name: 'id'
                        }, {
                            name: 'order_no'
                        }, {
                            name: 'position'
                        }, {
                            name: 'pnr'
                        }, {
                            name: 'status'
                        }, {
                            name: 'trx_status'
                        }, {
                            name: 'air_no'
                        }, {
                            name: 'price_sum'
                        }, {
                            name: 'fly_date'
                        }, {
                            name: 'fly_time'
                        }, {
                            name: 'created_at'
                        }, {
                            name: 'fromto'
                        }])
                });

                var ordergridpanel = new Ext.grid.GridPanel({
                    el: 'rtOrdersGrid',
                    ds: orderds,
                    cm: ordercm,
                    loadMask: true,
                    autoWidth: true,
                    collapsible: true,
                    animCollapse: true,
                    height: 100,
                    //frame: true,
                    title: '订单信息'
                });

                ordergridpanel.getStore().on({
                    //beforeload: function(){
                    load: function(){
                        var result = this.reader.jsonData.info;
                        if (result.indexOf("成功") < 0) {
                            Ext.MessageBox.alert("提取失败", "" + result);
                        }
                        else {
                            Ext.MessageBox.alert("提取成功", "" + result);
                        }
                        var oid = this.reader.jsonData.orderid;
                        if (oid != "") {
                            ticketds.baseParams.id = oid;
                            ticketds.reload();
                        }
                    }
                });

                ordergridpanel.render();
                //orderds.load();

                //### 机票Grid ###
                var ticketcm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
                        header: '编号',
                        dataIndex: 'id',
                        hidden: true
                    }, {
                        header: 'PNR',
                        dataIndex: 'pnr',
                        width: 60
                    }, {
                        header: '旅客姓名',
                        dataIndex: 'pass_name',
                        width: 70
                    }, {
                        header: '证件号码',
                        dataIndex: 'pass_card_id',
                        width: 140
                    }, {
                        header: '票号',
                        dataIndex: 'ticket_no',
                        width: 110
                        /*
                    }, {
                        header: '状态',
                        dataIndex: 'status',
                        width: 50
                         */
                    }, {
                        header: '机票价格',
                        dataIndex: 'price',
                        width: 60
                    }, {
                        header: '机场费税',
                        dataIndex: 'airdrome_tax',
                        width: 60
                    }, {
                        header: '附加费',
                        dataIndex: 'fuel_tax',
                        width: 60
                        /*
                    }, {
                        header: '保险份数',
                        dataIndex: 'insurance_number',
                        width: 60
                         */
                    }, {
                        header: '其他',
                        dataIndex: 'other',
                        width: 50
                    }, {
                        header: '合计',
                        dataIndex: 'total_price',
                        width: 60

                    }]);
                ticketcm.defaultSortable = true;
                var ticketds = new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: '/ticket/getTicketsByOrderID'
                    }),
                    reader: new Ext.data.JsonReader({
                        //totalProperty: 'totalProperty',
                        root: 'root'
                    }, [{
                            name: 'id'
                        }, {
                            name: 'pnr'
                        }, {
                            name: 'web_order_id'
                        }, {
                            name: 'pass_name'
                        }, {
                            name: 'pass_tel'
                        }, {
                            name: 'pass_card_id'
                        }, {
                            name: 'ticket_no'
                        }, {
                            name: 'price'
                        }, {
                            name: 'status'
                        }, {
                            name: 'airdrome_tax'
                        }, {
                            name: 'fuel_tax'
                        }, {
                            name: 'other'
                        }, {
                            name: 'total_price'
                        }, {
                            name: 'insurance_campany'
                        }, {
                            name: 'insurance_out_date'
                        }, {
                            name: 'insurance_number'
                        }, {
                            name: 'insurance_no'
                        }, {
                            name: 'insurance_type'
                        }])
                });

                var ticketgridpanel = new Ext.grid.GridPanel({
                    el: 'rtTicketsGrid',
                    ds: ticketds,
                    cm: ticketcm,
                    loadMask: true,
                    autoWidth: true,
                    collapsible: true,
                    animCollapse: true,
                    height: 180,
                    title: '乘客航班信息'
                });

                ticketgridpanel.render();
                //ticketds.load();

            })
        </script>
    </body>
</html>
